﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace BanVeXemPhim_Presentation
{
    public class NhomNguoiSuDungDAO:DataProvider
    {
        public NhomNguoiSuDungDTO[] LayDanhSachNhomNguoiSuDung()
        {
            connect();
            string query = "select * from NhomNguoiSuDung";
            adapter = new SqlDataAdapter(query, connection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            DataTable dataTable = dataSet.Tables[0];
            int n = dataTable.Rows.Count;
            NhomNguoiSuDungDTO[] nhomNguoiSuDungDtos = new NhomNguoiSuDungDTO[n];
            for (int i = 0; i < n; i++)
            {
                nhomNguoiSuDungDtos[i] = (NhomNguoiSuDungDTO)GetDataFromDataRow(dataTable, i);
            }
            return nhomNguoiSuDungDtos;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            NhomNguoiSuDungDTO nguoiSuDungDto=new NhomNguoiSuDungDTO();
            nguoiSuDungDto.IdNhomNguoiSuDung = Convert.ToInt32(dt.Rows[i]["IdNhomNguoiSuDung"].ToString());
            nguoiSuDungDto.TenNhom = dt.Rows[i]["TenNhom"].ToString();
            return nguoiSuDungDto;
        }


    }
}
